define(['bootstrap','bootstrapTable','layer'],function (bootstrap,bootstrapTable,layer) {
    return{
        init:function () {
            /*发送验证码*/
            $("#sendSMS").click(function(){
                layer.confirm('你确定要发送验证码用于修改密码？', {title:'发送验证码',icon: 3,
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.ajax({
                        url:"/loginController/setPwdSendSMS",
                        dataType:"json",
                        type:"post",
                        data:{
                            "phone1":$("#phone1").val(),
                            "phone2":$("#phone2").val()
                        },
                        success:function(result){
                            if(result.code == 10001){
                                console.log("id:" + result.data.id);
                                $("#id").val(result.data.id);
                                layer.msg(result.msg,{icon:1});
                            }
                        }
                    });
                });
            });
            /*检查验证码*/
            $("#submit").click(function(){
                $.ajax({
                    url:"/loginController/checkVerCode",
                    dataType:"json",
                    type:"post",
                    data:{
                        "id":$("#id").val(),
                        "phone1":$("#phone1").val(),
                        "code1":$("#code1").val(),
                        "phone2":$("#phone2").val(),
                        "code2":$("#code2").val()
                    },
                    success:function(result){
                        if(result.code == 10001){
                            layer.msg(result.msg,{icon:1});
                            openLayer('修改密码',$("#model"));
                        }else {
                            layer.msg(result.msg,{icon:2});
                        }
                    }
                });

            });

            /*修改密码*/
            $("#saveNewPwd").click(function(){
                $.ajax({
                    url:"/loginController/updatePwd",
                    dataType:"json",
                    type:"post",
                    data:{
                        "newPwd":$("#newPwd").val(),
                        "reNewPwd":$("#reNewPwd").val()
                    },
                    success:function(result){
                        if(result.code == 10001){
                            layer.msg(result.msg,{icon:1});
                        }else {
                            layer.msg(result.msg,{icon:2});
                        }
                    }
                });

            });


        }
    };
    function openLayer(title,$dom){
        layer.open({
            type: 1,
            title:title,
            anim: 2,
            closeBtn:1,
            area:["60%","80%"],
            content:$dom,
            cancel: function(index, layero){
                $dom.css({"display":"none"})
            }
        });
    }
});